import json
import datetime
import requests

data = '{"code":200,"msg":"用户办证信息查询成功!","data":{"sfzmhm":"370481199102063219","ylzqyms":"市界到二环 (不含二环路)+客车全年可办理12次，每次限通行7天","ylzmc":"进京证(六环内)","elzqyms":"市界到六环 (含六环路、不含通州全域)+客车全年不限办理次数，每次限通行7天","elzmc":"进京证(六环外)","bzclxx":null},"from":"v2"}'

if __name__ == '__main__':
    response = json.loads(data)
    _from = response['from']
    if _from == 'v2':
        bzclxx = response['data']['bzclxx']
        if bzclxx is None or bzclxx == []:
            print('申请进京证1')
        else:
            bzxx = bzclxx[0]['bzxx']
            ecbzxx = bzclxx[0]['ecbzxx']
            freeDay = 0
            if bzxx is not None and bzxx != []:
                for item in bzxx:
                    if item['sxsyts'] is None:
                        freeDay = 7
                    else:
                        freeDay = max(item['sxsyts'], freeDay)

            if ecbzxx is not None and bzxx != []:
                for item in ecbzxx:
                    if item['sxsyts'] is None:
                        freeDay = 7
                    else:
                        freeDay = max(item['sxsyts'], freeDay)
            if freeDay < 2:
                print("申请进京证2")
            else:
                print(f'{datetime.date.today()} 有效期还有：{freeDay}')
            # if (bzxx is None or bzxx == []) and (ecbzxx is None or ecbzxx == []):
            #     print('申请进京证')
            # else:
            #     freeDay = 0
            #     waitingCross = False
            #     for item in bzxx:
            #         freeDay = max(item['sxsyts'], freeDay)
            #         print(item['blztmc'])
            #         if '审核中' in item['blztmc'] or '待生效' in item['blztmc']:
            #             waitingCross = True
            #             pass
            #     if waitingCross:
            #         print(f'{datetime.date.today()} 有待生效的进京证')
            #     # 定时晚上八点执行，因此都是第二天开始的进京证
            #     elif freeDay <= 1:
            #         print('申请进京证')
            #     else:
            #         print(f'{datetime.date.today()} 有效期还有：{freeDay}')
    else:
        print('版本不一致，升级程序')
